package com.golang.api.controller;

import com.golang.api.common.domain.PageDTO;
import com.golang.api.dto.request.ActivityBasicDto;
import com.golang.api.dto.request.ActivitySearchDto;
import com.golang.api.dto.request.ActivitySettingDto;
import com.golang.api.dto.response.ActivityBasicRespDto;
import com.golang.api.dto.response.ActivityDetailDto;
import com.golang.api.dto.response.ActivityListRespDto;
import com.golang.api.dto.response.ActivitySettingRespDto;
import com.golang.api.service.IActivityService;
import com.golang.api.util.Result;
import com.golang.api.util.ResultGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动Controller
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@Slf4j
@RequestMapping("/api/activity")
public class ActivityController {

    @Autowired
    private IActivityService activityService;


    //创建、编辑基本信息
    @PostMapping(value = "/basic")
    public Result<String> createBasic(@ModelAttribute ActivityBasicDto basic) throws Exception {
        log.info("创建活动基本信息:{}", basic);
        return activityService.createBasic(basic);
    }


    //创建/修改报名设置信息
    @PostMapping(value = "/createSetting")
    public Result<Boolean> createSetting(@ModelAttribute ActivitySettingDto setting) throws Exception {
        log.info("创建/修改报名设置信息:{}", setting);
        return activityService.createSetting(setting) ? ResultGenerator.success(true) : ResultGenerator.error();
    }


    //发布
    @PostMapping(value = "/release")
    public Result<Boolean> release(@ModelAttribute ActivitySettingDto setting) throws Exception {
        log.info("发布活动:{}", setting);
        return activityService.release(setting);
    }


    //获取基本信息
    @PostMapping(value = "/getBasic")
    public Result<ActivityBasicRespDto> getBasic(@RequestParam String activityId) {
        log.info("获取活动基本信息:{}", activityId);
        return activityService.getBasic(activityId);
    }


    //获取报名设置信息
    @PostMapping(value = "/getSetting")
    public Result<ActivitySettingRespDto> getSetting(@RequestParam String activityId) {
        log.info("获取报名设置信息:{}", activityId);
        return activityService.getSetting(activityId);
    }


    //一键复制
    @PostMapping(value = "/copyHistory")
    public Result<String> copyHistory(@RequestParam String activityId) {
        log.info("一键复制活动:{}", activityId);
        return activityService.copyHistory(activityId);
    }


    //活动详情页
    @PostMapping(value = "/info")
    public Result<ActivityDetailDto> info(@RequestParam(required = true) String activityId) {
        log.info("活动详情页:{}", activityId);
        return activityService.info(activityId);
    }


    //活动列表(首页搜索)
    @PostMapping(value = "/list")
    public Result<PageDTO<ActivityListRespDto>> list(ActivitySearchDto dto) {
        return activityService.list(dto);
    }


    //活动取消
    @PostMapping(value = "/cancel")
    public Result<Boolean> cancel(@RequestParam String activityId) {
        return activityService.cancel(activityId);
    }


    //猜你喜欢
    @PostMapping(value = "/recommend")
    public Result<List<ActivityDetailDto>> recommend() {
        return activityService.recommend();
    }


}
